package com.xyebank.ledger.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * Created by CQ on 16/8/5.
 */
public class Jackson2TypedObjectMapper extends ObjectMapper {

    private static final long serialVersionUID = 4402127997078513582L;

    public Jackson2TypedObjectMapper() {
        //设置null值不参与序列化(字段不被显示)
        this.setSerializationInclusion(JsonInclude.Include.NON_NULL);

        // 禁用空对象转换json校验
        this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        // 启用类型记录
        this.enableDefaultTyping(DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    }
}